CategoriesPortlet = Class.extend({
	init: function()	{
		this.name = "CategoriesPortlet";
	},
	
	onBegin: function()	{
		this.registerObserver();
	},
	
	onEnd: function()	{
		this.unregisterObserver();
	},
	
	onReloadPage: function()	{
		this.run();
	},
	
	onShowCategoryProductTip: function(eventData)	{
		var type = eventData.type;
		if (type == 'Product')	{
			var product = this.currentProducts[eventData.index];
			showtip(this.renderView('Tooltip', product));
		}
	},
	
	run: function()	{
		//store the current object
		var obj = this;
		var id = this.getRequest().getParam('id');
		this.onAjax('categories', 'load-products', {id: id}, 'GET', {
			'onSuccess': function(ret)	{
				obj.model = {};
				obj.model.products = ret.data;
				for(var i=0;i<ret.data.length;i++) {
					if (ret.data[i].description != null)
						ret.data[i].description = ret.data[i].description.substr(0, 100)+'...';
				}
				obj.currentProducts = ret.data;
				if (ret.type == 'product')	{
					obj.model.page = 'Product';
				} else {
					obj.model.page = 'Categories';
				}
				obj.getPortletPlaceholder().paintCanvas(obj.render());
			}
		});
	}
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface).implement(ObserverInterface);